package com.faner.bean;


import java.io.Serializable;

/**
 * web端 消息结构
 *
 * @author Administrator
 */
public class ResultUtil<T> implements Serializable {

    private static final long serialVersionUID = 6054827931086878783L;

    public static <T> ResultUtil<T> build(int code, T dataInfo) {
        ResultUtil<T> resultUtil = new ResultUtil<T>();
        resultUtil.setCode(code);
        resultUtil.setData(dataInfo);
        return resultUtil;
    }

    public static <T> ResultUtil<T> build(int code) {
        return build(code, null);
    }

    public static <T> ResultUtil<T> build(T dataInfo) {
        return success(dataInfo);
    }

    public static <T> ResultUtil<T> success(T dataInfo) {
        return build(0, dataInfo);
    }

    public final static ResultUtil<Void> SIMPLE_SUCCESS = new ResultUtil<>();

    public final static ResultUtil<Void> SIMPLE_UNKNOW_ERROR = ResultUtil.build(1);

    private int code = 0;

    private T data = null;

    public ResultUtil() {
    }

    public ResultUtil(int c) {
        this.code = c;
    }

    public boolean success() {
        return code == 0;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
